package com.ruoyi.jinchuguanli.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jinchuguanli.domain.Tuihuochuli;
import com.ruoyi.jinchuguanli.domain.TuihuochuliReturn;
import com.ruoyi.jinchuguanli.service.ITuihuochuliService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * tuihuoController
 *
 * @author ruoyi
 * @date 2023-11-08
 */
@Controller
@RequestMapping("/jinchuguanli/tuihuo")
public class TuihuochuliController extends BaseController {
    private final String prefix = "jinchuguanli/tuihuo";

    @Autowired
    private ITuihuochuliService tuihuochuliService;

    @RequiresPermissions("jinchuguanli:tuihuo:view")
    @GetMapping()
    public String tuihuo () {
        return prefix + "/tuihuo";
    }

    /**
     * 查询tuihuo列表
     */
    @RequiresPermissions("jinchuguanli:tuihuo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list (Tuihuochuli tuihuochuli) {
        startPage();
//        List<Tuihuochuli> list = tuihuochuliService.selectTuihuochuliList(tuihuochuli);
        List<TuihuochuliReturn> list = tuihuochuliService.selectTuihuochuliReturnList(tuihuochuli);
        return getDataTable(list);
    }

    /**
     * 导出tuihuo列表
     */
    @RequiresPermissions("jinchuguanli:tuihuo:export")
    @Log(title = "tuihuo", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export (Tuihuochuli tuihuochuli) {
        List<TuihuochuliReturn> list = tuihuochuliService.selectTuihuochuliReturnList(tuihuochuli);
        ExcelUtil<TuihuochuliReturn> util = new ExcelUtil<TuihuochuliReturn>(TuihuochuliReturn.class);
        return util.exportExcel(list, "退货数据");
    }

    /**
     * 新增tuihuo
     */
    @GetMapping("/add")
    public String add () {
        return prefix + "/add";
    }

    /**
     * 新增保存tuihuo
     */
    @RequiresPermissions("jinchuguanli:tuihuo:add")
    @Log(title = "tuihuo", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave (Tuihuochuli tuihuochuli) {
        tuihuochuli.setZhixing("未执行");
        return toAjax(tuihuochuliService.insertTuihuochuli(tuihuochuli));
    }

    /**
     * 修改tuihuo
     */
    @RequiresPermissions("jinchuguanli:tuihuo:edit")
    @GetMapping("/edit/{id}")
    public String edit (@PathVariable("id") Integer id, ModelMap mmap) {
        Tuihuochuli tuihuochuli =
                tuihuochuliService.selectTuihuochuliById(id);
        mmap.put("tuihuochuli", tuihuochuli);
        return prefix + "/edit";
    }

    /**
     * 修改保存tuihuo
     */
    @RequiresPermissions("jinchuguanli:tuihuo:edit")
    @Log(title = "tuihuo", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave (Tuihuochuli tuihuochuli) {
        return toAjax(tuihuochuliService.updateTuihuochuli(tuihuochuli));
    }

    /**
     * 删除tuihuo
     */
    @RequiresPermissions("jinchuguanli:tuihuo:remove")
    @Log(title = "tuihuo", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove (String ids) {
        return toAjax(tuihuochuliService.deleteTuihuochuliByIds(ids));
    }
}
